import { axiosInstance } from 'src/boot/axios'
import CommonConfig from 'src/assets/js/config'

const baseUrl = CommonConfig.upmsUrl + '/v1'
const datacenterUrl = CommonConfig.datacenterUrl + '/v1'

// 列举用户信息
export function getUser (userId) {
  const newUrl = `${datacenterUrl}/users/${userId}`

  return axiosInstance.get(newUrl).then((res) => {
    return Promise.resolve(res)
  })
}

// 修改密码
export function editPassWord (query, userId) {
  const url = `${datacenterUrl}/users/${userId}/password`

  let params = {
    ...query
  }

  return axiosInstance.put(url, params).then(resp => {
    return Promise.resolve(resp)
  })
}

/**
 * 修改手机号
 * @param params
 */
export function changePhone (params) {
  const url = `${datacenterUrl}/account/change/phone`

  return axiosInstance.put(url, params).then(resp => {
    return Promise.resolve(resp)
  })
}

/**
 * 验证密码
 */
export function validatePassword (params) {
  const url = `${datacenterUrl}/account/validate/password`

  return axiosInstance.post(url, null, { params }).then(resp => {
    return Promise.resolve(resp)
  })
}

// 增量编辑用户
export function editUser (id, photoUrl) {
  const url = datacenterUrl + '/users/' + id

  let reqData = {
    photoUrl
  }

  return axiosInstance.patch(url, reqData).then(resp => {
    return Promise.resolve(resp)
  })
}

/**
 * 获取当前企业有期限的权限
 * clientType 客户端类型(pc,mobile)
 */
export function getPrivileges (params) {
  const newUrl = `${baseUrl}/time_limit/company_view_privileges`

  return axiosInstance.get(newUrl, { params }).then((res) => {
    return Promise.resolve(res)
  })
}
/**
 * 查询模块服务期限列表
 */
// /v1/user/{userId}/service_period
export function getServicePeriod (userId) {
  const newUrl = `${baseUrl}/user/${userId}/service_period`

  return axiosInstance.get(newUrl).then((res) => {
    return Promise.resolve(res)
  })
}
